<?php
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

//********************************
//*
//*           public main
//*
//*******************************/
include 'core/WsSocialManager.php';
include 'core/libs/utils.php';

// verification des paramettres GET
$checks = array('title','article', 'count', 'type');
foreach($_POST as $key=>$ck){
    if(!in_array($key, $checks)){
        header('HTTP/1.0 406 Not acceptable');
        echo "parametres errones envoyes ".print_r($_POST, true);
        exit;
    }
}

// initialisation du webservice
$ws = new WsSocialManager();

//envoi des messages
$location = $ws->sendMessage($_POST['title'], $_POST['article']);

// verification code retour
if(strstr($ws->getResponseCode(), "200")){
    echo $location;
}
else {
    // gestion des erreurs
    header("HTTP/1.0 502 bad gateway");
    echo "WS distant a rependu ".$ws->getResponseCode().' : '.getHttpCodeDescription($ws->getResponseCode(), true);
}